/**
 * 
 */
package com.github.phoenics.militia.common.exception;

import java.io.Serializable;

/**
 * @author Phoenics Chow 
 * on 2018年5月18日
 *
 */
public class BaseResult implements Serializable{
	private static final long serialVersionUID = 1L;
	public static final int SUCCESS_CODE=0;
	public static final int EXCEPTION_CODE=1;
	public static final String EXCEPTION_MESSAGE="系统错误";
	//private static final String EXCEPTION_CONTENT = "; content:\n";
	
	// 0:success   other:error
	private Integer code=0;
	private String message="ok";
	private  Object data=null;
	private long time=System.currentTimeMillis();
	private String token="";
	public BaseResult(){

	}

	private BaseResult(Integer code,String message){
		this.code=code;
		this.message=message;
	}

	private BaseResult(String message,Object data){
		this.message=message;
		this.data=data;
	}
	private BaseResult(Object data){
		setData(data);
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getmessage() {
		return message;
	}

	public void setmessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public boolean isSuccess(){
		return  code==SUCCESS_CODE;
	}
	public static  BaseResult  fail(int code,String message){
		return new BaseResult (code,message);
	}
	public static  BaseResult  success(int code,String message){
		return new BaseResult (code,message);
	}

	public static  BaseResult  fail(String message){
		return new BaseResult (EXCEPTION_CODE,message);
	}
	public static  BaseResult  fail(){
		return new BaseResult (EXCEPTION_CODE,EXCEPTION_MESSAGE);
	}

	public static  BaseResult  successmessage(String message){
		return new BaseResult (message,null);
	}

	public static  BaseResult  success(Object data){
		BaseResult b=new BaseResult ();
		b.setData(data);
		return b;
	}
	public static  BaseResult  success(){
		return new BaseResult (null);
	}

	public static  BaseResult  success(String message,Object data){
		return new BaseResult (message,data);
	}


	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}
}
